package com.example.sxy_project;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private LinearLayout mMenuWeixin;
    private LinearLayout mMenuTongxunlu;
    private LinearLayout mMenuFaxian;
    private LinearLayout mMenuWode;

    private WeixinFragment weixinFragment = new WeixinFragment();
    private TongxunluFragment tongxunluFragment = new TongxunluFragment();
    private FaxianFragment faxianFragment = new FaxianFragment();
    private WodeFragment wodeFragemnt = new WodeFragment();

    ImageView weixinImg;
    ImageView tongxunImg;
    ImageView faxianImg;
    ImageView wodeImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        weixinImg = (ImageView) findViewById(R.id.caidan_weixin);
        tongxunImg = (ImageView) findViewById(R.id.caidan_tongxun);
        faxianImg = (ImageView) findViewById(R.id.caidain_faxian);
        wodeImg = (ImageView) findViewById(R.id.caidan_wode);


        this.getSupportFragmentManager().beginTransaction()
                .add(R.id.container_content,weixinFragment)
                .add(R.id.container_content,tongxunluFragment)
                .add(R.id.container_content,faxianFragment)
                .add(R.id.container_content,wodeFragemnt)
                .hide(tongxunluFragment).hide(faxianFragment)
                .hide(wodeFragemnt).commit();
    }

    private void initView() {
        mMenuWeixin = this.findViewById(R.id.menu_weixin);
        mMenuTongxunlu = this.findViewById(R.id.menu_tongxunlu);
        mMenuFaxian = this.findViewById(R.id.menu_faxian);
        mMenuWode = this.findViewById(R.id.menu_wode);

        mMenuWeixin.setOnClickListener(this);
        mMenuTongxunlu.setOnClickListener(this);
        mMenuFaxian.setOnClickListener(this);
        mMenuWode.setOnClickListener(this);
    }

    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.menu_weixin:
                weixinImg.setImageResource(R.drawable.weixin);
                tongxunImg.setImageResource(R.drawable.tongxunlu);
                faxianImg.setImageResource(R.drawable.faxian);
                wodeImg.setImageResource(R.drawable.wo);
                this.getSupportFragmentManager().beginTransaction()
                        .show(weixinFragment).hide(tongxunluFragment)
                        .hide(faxianFragment).hide(wodeFragemnt)
                        .commit();break;
            case R.id.menu_tongxunlu:
                weixinImg.setImageResource(R.drawable.weixin);
                tongxunImg.setImageResource(R.drawable.tongxunlu);
                faxianImg.setImageResource(R.drawable.faxian);
                wodeImg.setImageResource(R.drawable.wo);
                this.getSupportFragmentManager().beginTransaction()
                        .show(tongxunluFragment).hide(weixinFragment)
                        .hide(faxianFragment).hide(wodeFragemnt)
                        .commit();break;
            case R.id.menu_faxian:
                weixinImg.setImageResource(R.drawable.weixin);
                tongxunImg.setImageResource(R.drawable.tongxunlu);
                faxianImg.setImageResource(R.drawable.faxian);
                wodeImg.setImageResource(R.drawable.wo);
                this.getSupportFragmentManager().beginTransaction()
                        .show(faxianFragment).hide(weixinFragment)
                        .hide(tongxunluFragment).hide(wodeFragemnt)
                        .commit();break;
            case R.id.menu_wode:
                weixinImg.setImageResource(R.drawable.weixin);
                tongxunImg.setImageResource(R.drawable.tongxunlu);
                faxianImg.setImageResource(R.drawable.faxian);
                wodeImg.setImageResource(R.drawable.wo);
                this.getSupportFragmentManager().beginTransaction()
                        .show(wodeFragemnt).hide(tongxunluFragment)
                        .hide(faxianFragment).hide(weixinFragment)
                        .commit();break;
            default:break;
        }
    }
}

